package com.schoolET.controller.admin;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.schoolET.result.MyPage;
import com.schoolET.result.Result;
import com.schoolET.service.IChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户之间的聊天内容 前端控制器
 * </p>
 *
 * @author le
 * @since 2024-06-04
 */
@Api(tags = "用户之间的聊天内容")
@RestController
@RequestMapping("/schoolET")
public class ChatController {

    @Resource
    private IChatService chatService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "le")
    @ApiOperation(value = "查询用户之间的聊天内容所有数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "position",value = "位置信息",required = true),
            @ApiImplicitParam(name = "nickname",value = "用户名"),
    })
    @GetMapping("/chatList")
    public Result findChat(
            String position,
            String nickname,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize
    ) {
        if (position == null) {
            return Result.error().msg("位置信息必填");
        }
        return Result.success(MyPage.page(chatService.findChat(position,nickname,pageNum,pageSize))).msg("查询成功");
    }


    /**
     * 删除聊天记录
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "le")
    @ApiOperation(value = "删除聊天记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "chatId",required = true)
    })
    @DeleteMapping("/chatDel/{id}")
    public Result<String> delete(@PathVariable Integer id) {
        chatService.removeById(id);
        return Result.success().msg("删除成功");
    }

}